<template>
  <div style="display: flex; font-size: 12px;line-height: 60px">
    <div style="flex: 1;font-size: 20px">
      <span :class="collapseBtnClass" style="cursor:pointer" @click="collapse"></span>
      <el-breadcrumb separator="/" style="display: inline-block;margin-left: 3px">
        <el-breadcrumb-item
            :to="{path:v.path}" v-for="(v,i) in list" :key="i"
        >{{ v.name }}
        </el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <el-dropdown style="width: 75px;cursor: pointer" trigger="hover">
      <span>{{username}}<i class="el-icon-arrow-down" style="margin-left: 5px"></i></span>
      <el-dropdown-menu slot="dropdown">
        <el-dropdown-item @click.native="$router.push('/person')">个人信息</el-dropdown-item>
        <el-dropdown-item @click.native="logout">退出登录</el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
  </div>
</template>

<script>
export default {
  name: "Header",
  data() {
    return {
      list: [],
      username:JSON.parse(localStorage.getItem("user")).username
    }
  },
  created() {
    this.list = this.$route.matched;
  },
  props: {
    collapseBtnClass: String,
    collapse: Function
  },
  watch: { //路由改变的时候监听
    $route(to, from) {
      this.list = to.matched
    }
  },
  methods:{
    logout() {
      this.$store.commit("logout")
      this.$message.success("退出成功")
    }
  }
}
</script>

<style scoped>
.el-breadcrumb__separator {
  margin: 0 2px;
}
</style>
